﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ApplicationLibrary.DBManager;
using ApplicationLibrary.ExtendedControls;
using Plumber.Accounting.ModuleData;
using ApplicationLibrary.SqlConnector;
using ApplicationLibrary;

namespace Plumber.Accounting.Forms
{
    public partial class LiquidationYearType : ApplicationLibrary.DBManager.DocumentForm
    {
        private EnumsManager<LiquidationType> eType = null;

        public LiquidationYearType()
            : base(Properties.Resources.FN_LiquidationType)
        {
            InitializeComponent();
        }

        protected override void OnAttachData()
        {
            for (int t = 2011; t <= GlobalInfo.CurrentDate.Year; t++)
                cbbYear.Items.Add(t);

            dbManager = new dbmanagerLiquidationType("dbmanagerLiquidationTypeForm", new RadarLiquidationType(), this);
            dbManager.AddMaster(this, PL_LiquidationType.Name, true);

            eType = new EnumsManager<LiquidationType>(cbbType);
            base.OnAttachData();
        }

        protected override void OnBindData()
        {
            BindControl(cbbType, PL_LiquidationType.Type, "SelectedValue", NullValue.NotSet);
            BindControl(cbbYear, PL_LiquidationType.Year, "Text", NullValue.NotSet);
        }

        protected override void OnDisableControlsForEdit()
        {
            cbbYear.Enabled = false;

            base.OnDisableControlsForEdit();
        }

    }
    #region DbManager dbmanagerLiquidationType

    /// <summary>
    /// Classe derivata per gestioni particolari
    /// </summary>
    internal class dbmanagerLiquidationType : DBManager
    {
        public dbmanagerLiquidationType(string name, RadarForm radar, DocumentForm document)
            : base(name, radar, document)
        { }

        protected override string CreateMasterQuery()
        {
            this.Table = new PL_LiquidationType();
            QueryBuilder qB = new QueryBuilder();
            qB.AddSelect();
            qB.AddFrom(this.Table);
            qB.AddCompare(PL_LiquidationTax.Year, "@p1");

            return qB.Query;
        }

        protected override List<SqlABParameter> CreateMasterParam()
        {
            List<SqlABParameter> PList = new List<SqlABParameter>();

            SqlABParameter p1 = new SqlABParameter("@p1", PL_LiquidationType.Year);
            p1.Value = PL_LiquidationType.Year.DefaultValue;
            PList.Add(p1);

            return PList;
        }

        protected override void SetParameters(IRadarParameters key, DBCollection collection)
        {
            collection.Parameter[0].Value = key[0];
        }
    }

    #endregion DbManager dbmanagerLiquidationTax
}
